<%@page import="cn.ticket.Constant"%>
<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@page import="org.apache.catalina.Session"%>
<%@ page import="java.sql.Date,java.sql.*"%>
<%@ page import="cn.ticket.db.DBConnect"%>
<%@ page import="cn.ticket.util.StringUtil"%>
<%@ page import="cn.ticket.util.CommonEncryption"%>
<% 
	request.setCharacterEncoding("utf8" ) ;
	String  email=request.getParameter("email") ;
	String password = request.getParameter("password") ;
	
	if(null==email || "".equals(email)){
		session.setAttribute("errorinfo", Constant.ERRORINFO_PARAMETERNULL) ;
		%>
		<jsp:forward page="/front/result.jsp" />
		<%
	}
	if(null==password || "".equals(password) ){
		session.setAttribute("errorinfo", Constant.ERRORINFO_PARAMETERNULL) ;
		%>
		<jsp:forward page="/front/result.jsp" />
		<%
	}else{
		password = new CommonEncryption().encryptByMD5toSHA1(password) ;
	}
	Connection con = new DBConnect().DBConnection() ;
	try {
		PreparedStatement pstmt =  con.prepareStatement("select * from user where email=? and (status=0 or status=1)") ;
		pstmt.setString(1,email) ;
		ResultSet rs = pstmt.executeQuery() ;
		if(rs.next()){
			if(password.equals(rs.getString(3))){
				session.removeAttribute("login_user_name") ;
				session.setAttribute("login_user_name", rs.getString(2)) ;
				session.removeAttribute("login_user_type") ;				
				session.setAttribute("login_user_type", rs.getString(5)) ;
				session.removeAttribute("login_user_id") ;				
				session.setAttribute("login_user_id", rs.getString(1)) ;
				
				if(rs.getInt(5)==Constant.USER_ADMIN){
					%>
						<jsp:forward page="/front/user/home_admin.jsp" />
					<%
				}else if(rs.getInt(5)==Constant.USER_PARTNER){
					%>
					<jsp:forward page="/front/user/home_partner.jsp" />
				<%	
				}else if(rs.getInt(5)==Constant.USER_COMUSER){
					%>
					<jsp:forward page="/front/user/home_comUser.jsp" />
				<%	
			}else{
				session.setAttribute("errorinfo", Constant.ERRORINFO_NETERROR) ;
				%>
				<jsp:forward page="/front/result.jsp" />
			<%
				}
			}
		}else{
			session.setAttribute("errorinfo", "账号or密码不正确,请重新确认后再操作.") ;
		%>
		<jsp:forward page="/front/login.jsp" />
	<%
	}
	}catch(Exception e){
		out.print("发生异常了."+e.getMessage()) ;
		session.setAttribute("errorinfo", Constant.ERRORINFO_NETERROR) ;
		%>
		<jsp:forward page="/front/result.jsp" />
		<%
	}
	%>
<%
%>